package com.itheima.test2;

import com.itheima.domain.Student;

import java.io.*;

/*
创建多个学生类对象写到文件中,再次读取到内存中


 */
public class Test03 {

    public static void main(String[] args) throws IOException, ClassNotFoundException {

        //method01();
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("day13\\students.txt"));
        while (true) {
            try {
                Student s1= (Student) ois.readObject();
                System.out.println(s1);
            } catch (EOFException e) {
                System.out.println("到头了兄弟");
                break;
            }
        }

       ois.close();
    }

    public static void method01() throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("day13\\students.txt"));
        Student cai = new Student("蔡徐坤", 28, "淖马村");
        Student wu = new Student("吴亦凡", 28, "海淀监狱");
        Student li = new Student("李云迪", 28, "朝阳派出所");
        oos.writeObject(cai);
        oos.writeObject(wu);
        oos.writeObject(li);

        oos.close();
    }
}
